//笔试强训：最长无重复子数组

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param arr int整型vector the array
     * @return int整型
     */
    int maxLength(vector<int>& arr) {
        // write code here
        unordered_set<int> s;
        int left = 0, right = 0;
        int n = arr.size(), maxLen = 0;
        while(right < n)
        {
            if(left == right || !s.count(arr[right]))
            {
                s.insert(arr[right]);
                right++;
            }
            else
            {
                maxLen = max(maxLen, right - left);
                while(s.count(arr[right]))
                {
                    s.erase(arr[left]);
                    left++;
                }
            }
        }
        maxLen = max(maxLen, right - left);

        return maxLen;
    }
};